import { dispatchFn } from "./modules/index";
export const commonApiUrl =
  "https://www.fastmock.site/mock/39acd36bd50260472127df16096f1094/uniins";
export const request = {
  async api(url, data, config) {
    const result = await fetch(commonApiUrl + url, {
      mode: "cors",
      headers: {
        "Content-Type": "application/json;charset=UTF-8",
        Token: localStorage.getItem("Token") || "",
      },
      cache: "default",
      ...config,
    });

    return result.json();
  },
  async post(url, data, config) {
    config = config || {};
    return await this.api(url, data, {
      method: "post",
      body: JSON.stringify(data),
      ...config,
    });
  },
  async get(url, data, config) {
    config = config || {};
    return await this.api(url, data, { method: "post", ...config });
  },
  async dispatch(name, options) {
    return await dispatchFn[name](request, options);
  },
};
